let mongoose = require('mongoose'),
    async = require('async'),
    categorys = mongoose.model('categorys'),
    memberUsers = mongoose.model('member_users');

module.exports = (req, res) => {
    let params = req.query;

    if(!params.mobile){
        res.json(resFail('请先登陆'));
        return false;
    }

    async.series([
        // 获取用户信息
        callback => {
            memberUsers.findOne({
                mobile: params.mobile
            }, (err, doc) => {
                if(err){
                    res.json(resFail(err))
                }else{
                    this.userInfo = doc;
                    callback();
                }
            })
        },
        // 获取类目信息
        callback => {
            categorys.findOne().sort({'createTime': -1})
            .exec((err, doc) => {
                if(err){
                    res.json(resFail(err))
                }else{
                    this.category = doc.categorys;
                    callback();
                }
            })
        },
        // 组合输出
        callback => {
            let userInfo = this.userInfo;
            res.json({
                result: 1,
                data: {
                    // 用户信息
                    birthday: userInfo.birthday,
                    autograph: userInfo.autograph,
                    userGroup: userInfo.userGroup,
                    avater: userInfo.avater,
                    sex: userInfo.sex,
                    address: userInfo.address,
                    integral: userInfo.integral,
                    mobile: userInfo.mobile,
                    email: userInfo.email,
                    userName: userInfo.userName,
                    speciality: userInfo.speciality,
                    comeFrom: userInfo.comeFrom,
                    // category
                    categorys: this.category
                }
            })
        }
    ])
}